package com.zito.health.service.impl;


import com.zito.health.entity.Unit;
import com.zito.health.mapper.DepartmentMapper;
import com.zito.health.mapper.UnitMapper;
import com.zito.health.service.UnitService;
import com.zito.health.vo.UnitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @author: gxt
 * @time: 2019/11/8 14:56
 */
@Service
public class UnitServiceImpl implements UnitService {

    @Autowired
    private UnitMapper unitMapper;
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public Unit save(Unit object) {
        int res = unitMapper.insertSelective(object);
        return object;
    }

    @Override
    @Transactional
    public void delete(Integer id) {
        departmentMapper.deleteByUnitId(id);
        unitMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Unit object) {
        unitMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public List<Unit> query() {
        return unitMapper.selectAll();
    }

    @Override
    public List<Unit> query(Unit object) {
        return unitMapper.select(object);
    }

    @Override
    public Unit queryOne(Unit object) {
        return unitMapper.selectOne(object);
    }

    @Override
    public Unit queryById(Integer id) {
        Unit object = unitMapper.selectByPrimaryKey(id);
        return object;
    }

    @Override
    public boolean exists(Integer id) {
        return unitMapper.existsWithPrimaryKey(id);
    }

    @Override
    public List<UnitVo> queryList(Unit param) {
        return unitMapper.queryList(param);
    }

    @Override
    public List<Unit> validateUnitname4Update(Unit u) {
        return unitMapper.validateUnitname4Update(u);
    }

    @Override
    public Integer verificationSingle(Integer unitId,Integer roleId) {
        return unitMapper.verificationSingle(unitId,roleId);
    }
}
